package com.applet.controller.admin;

import com.applet.common.vo.Result;
import com.applet.pojo.dto.PublishStudioDTO;
import com.applet.pojo.entity.Studio;
import com.applet.pojo.dto.UpdateStudioDTO;
import com.applet.service.StudioService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author “XuShao”
 * @date 2024/12/20 15:29
 * @description
 */
@RestController
@RequestMapping("/admin/studio")
@Slf4j
@Tag(name = "工作室相关接口")
public class StudioController {

    @Autowired
    private StudioService studioService;

    @Operation(summary = "添加工作室活动")
    @PostMapping
    public Result<?> addStudio(@RequestBody @Validated PublishStudioDTO publishStudioDTO) {
        log.info("添加工作室活动 => {}", publishStudioDTO);

        studioService.addStudio(publishStudioDTO);

        return Result.success();
    }

    @Operation(summary = "修改工作室活动")
    @PutMapping
    public Result<?> updateStudio(@RequestBody @Validated UpdateStudioDTO updateStudioDTO) {
        log.info("修改工作室活动 => {}", updateStudioDTO);

        studioService.updateStudio(updateStudioDTO);

        return Result.success();
    }

    @Operation(summary = "获取所有工作室活动")
    @GetMapping
    public Result<List<Studio>> getAllStudio() {
        log.info("=== 获取所有工作室活动 ===");

        List<Studio> studioAll = studioService.getStudioAll();

        return Result.success(studioAll);
    }

    @Operation(summary = "删除活动")
    @DeleteMapping("{id}")
    public Result<?> deleteStudio(@PathVariable String id) {
        log.info("删除活动 => {}", id);

        studioService.removeById(id);

        return Result.success();
    }
}
